package com.bocai.kelalacar.ui.car.set.ada;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelalacar.R;
import com.bocai.kelalacar.base.BaseRecyclerViewHolder;
import com.bocai.kelalacar.bean.CarDriverBean;
import com.bocai.kelalacar.ui.car.set.act.AddDriverActivity;
import com.bocai.kelalacar.ui.car.set.presenter.AddDriverPresenter;
import com.bocai.kelalacar.widget.ListBaseAdapter;

/**
 * Created by yuanfei on 2017/6/23.
 */

public class DriverMangerAda extends ListBaseAdapter<CarDriverBean.ContentBean.DriverListBean> {

    private AddDriverPresenter presenter;

    public DriverMangerAda(Context context,AddDriverPresenter presenter) {
        super(context);
        this.presenter = presenter;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_driver_manage;
    }

    @Override
    public void onBindItemHolder(BaseRecyclerViewHolder holder, final int position) {
        LinearLayout llDelete = (LinearLayout) holder.findView(R.id.ll_delete);
        TextView tvName = (TextView) holder.findView(R.id.tv_name);
        TextView tvPhone = (TextView) holder.findView(R.id.tv_phone);
        LinearLayout llDriver = (LinearLayout) holder.findView(R.id.ll_driver);

        tvName.setText(mDataList.get(position).getDriverName());
        tvPhone.setText(mDataList.get(position).getDriverPhone());

        llDriver.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(new Intent(mContext, AddDriverActivity.class).putExtra("name",mDataList.get(position).getDriverName())
                        .putExtra("phone",mDataList.get(position).getDriverPhone()).putExtra("id",mDataList.get(position).getDriverId()));
            }
        });

        llDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.deleteDriver(mDataList.get(position).getDriverId(),position);
            }
        });
    }
}
